/**
 * 系统名称: 企业财资
 * 模块名称: repair-boot
 * 类 名 称: ScheduledEventServiceBean.java
 * 软件版权: 恒生电子股份有限公司
 * 修改记录:
 * 修改人员:
 * 修改说明:
 * ============ ============================================
 * zhanghong 创建
 * ============ ============================================
 */
package com.mt.repair.service.repairManagement.impl;

import com.mt.common.core.security.RedisUtil;
import com.mt.common.core.utils.ScheduledUtils;
import com.mt.repair.utils.GetSerialNum;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.lang.reflect.Method;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 *
 *
 * @author zhanghong
 * @date 2023-03-17 18:52
 */
@Service
public class ScheduledEventServiceBean implements InitializingBean {
    Logger logger= LoggerFactory.getLogger(ScheduledEventServiceBean.class);
    @Autowired
    private RedisUtil redisUtil;
    SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    public void refreshOrderCode(){
        logger.info("重置订单编号，时间是："+sdf1.format(new Date()));
        redisUtil.set(GetSerialNum.repairNum,0);
        logger.info("重置订单编号成功，时间是："+sdf1.format(new Date()));
    }

    public void refreshDeviceCode(){
        logger.info("重置设备编号，时间是："+sdf1.format(new Date()));
        redisUtil.set(GetSerialNum.deviceLock,0);
        logger.info("重置设备编号成功，时间是："+sdf1.format(new Date()));
    }


    @Override
    public void afterPropertiesSet() throws Exception {
        String name=this.getClass().getSimpleName();
        Method[] declaredMethods = this.getClass().getDeclaredMethods();
        List<String> res=new ArrayList<>();
        for (int i = 0; i < declaredMethods.length; i++) {
            if(!"afterPropertiesSet".equals(declaredMethods[i].getName())) {
                res.add(declaredMethods[i].getName());
            }
        }
        char[] cs=name.toCharArray();
        cs[0]+=32;
        name=new String(cs);
        ScheduledUtils.serviceMap.put(name,res);
    }
}
